package com.studycloud.controller;

import com.netflix.hystrix.contrib.javanica.annotation.DefaultProperties;
import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand;
import com.studycloud.service.PaymentFeignHystrixService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;


/**
 * @author JP
 */
@RestController
@Slf4j
@DefaultProperties(defaultFallback = "paymentInfo_NOHandler")
public class OrderHystrixController
{
    @Resource
    private PaymentFeignHystrixService paymentFeignService;

    /**
     * 正常访问测试  hystrix
     * @param id
     * @return
     */
    @GetMapping(value = "/consumer/payment/hystrix/paymentinfo_ok/{id}")
    public String paymentInfo_OK(@PathVariable("id")Integer id)
    {
        log.info(paymentFeignService.paymentInfo_OK(id));
        return paymentFeignService.paymentInfo_OK(id);
    }
    /**
     * 错误访问测试  hystrix
     * @param id
     * @return
     */
    @GetMapping(value = "/consumer/payment/hystrix/paymentinfo_no/{id}")
    @HystrixCommand
    public String paymentInfo_NO(@PathVariable("id")Integer id)
    {
        int age = 10/0;
        log.info(paymentFeignService.paymentInfo_NO(id));
        return paymentFeignService.paymentInfo_NO(id);
    }

    /**
     * // 下面是全局fallback方法
     * Hystrix 备胎
     * @return
     */
    public String paymentInfo_NOHandler()
    {
        return ".....你的问题我帮你解决了";
    }
}
